package com.nine.system.controller;

import com.alibaba.fastjson.JSON;
import com.nine.common.pojo.Permission;
import com.nine.common.pojo.User;
import com.nine.common.vo.Result;
import com.nine.system.service.PermissionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: nine-education-parent
 * @author: ♥丁新华
 * @create: 2023-05-23 18:53
 **/
@RestController
@RequestMapping("/system/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @Autowired
    private StringRedisTemplate template;

    @GetMapping("leftMenu1")
    @ApiOperation (value = "获取左侧菜单数据")
    public Result leftMenu(HttpServletRequest request){
        //获取头信息
        String token = request.getHeader ("token");

        //获取用户信息
        String s = template.opsForValue ().get ("user::" + token);
        //转成json
        User aclUser = JSON.parseObject (s, User.class);

        List<Permission> aclPermissions = permissionService.selectByUserID (aclUser.getId ());

        return Result.success (aclPermissions);
    }
}
